import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const routes = [{
        path: '/',
        name: 'index',
        meta: {
            title: "首页"
        },
        component: () =>
            import ("@/views/Index.vue")
    },
    {
        path: '/login',
        name: 'login',
        meta: {
            title: "登录"
        },
        component: () =>
            import ("@/views/Login.vue")
    },
    {
        path: '/shipmentList',
        name: 'ShipmentList',
        meta: {
            title: "发货单列表"
        },
        component: () =>
            import ("@/views/ShipmentList.vue")
    },
    {
        path: '/myShipment',
        name: 'myShipment',
        meta: {
            title: "我的发货"
        },
        component: () =>
            import ("@/views/MyShipment.vue")
    },
    {
        path: '/shipmentDetail/:id',
        name: 'shipmentDetail',
        meta: {
            title: "发货"
        },
        component: () =>
            import ("@/views/ShipmentDetail.vue")
    },
    {
        path: '/handoverList',
        name: 'handoverList',
        meta: {
            title: "出库交接列表"
        },
        component: () =>
            import ("@/views/HandoverList.vue")
    },
    {
        path: '/myHandover',
        name: 'myHandover',
        meta: {
            title: "我的交接"
        },
        component: () =>
            import ("@/views/MyHandover.vue")
    },
    {
        path: '/handoverDetails/:id',
        name: 'handoverDetails',
        meta: {
            title: "交接"
        },
        component: () =>
            import ("@/views/HandoverDetails.vue")
    }, {
        path: '/damageRegistration',
        name: 'damageRegistration',
        meta: {
            title: "破损登记列表"
        },
        component: () =>
            import ("@/views/DamageRegistration.vue")
    },
]



const router = new VueRouter({
    base: process.env.BASE_URL,
    routes,
})
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    };
    if (window.localStorage.getItem('token')) {
        next();
    } else {
        if (to.path == '/login') {
            next();
        } else {
            try {
                window.appPlat.goLoginPage(getLocalhostUrl() + "/login");
            } catch (e) {
                next('/login');
            }
        }

    }

});

export default router